﻿#include "widget.h"
#include "ui_widget.h"
#include <QQuickWidget>
#include <QPixmap>
#include <QPalette>
#include <QColor>
#include <QQmlEngine>
#include <QQmlContext>
#include <QDate>
#include <QSettings>
#include <QDir>
#include <QTextStream>
#include <QDesktopWidget>
#include <QApplication>
#include <QDebug>

#include "game.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget),
    w(400),
    h(300)
{
    ui->setupUi(this);

    ui->quickWidget->engine()->rootContext()->setContextProperty("widget",this);

    ui->quickWidget->setSource(QUrl("qrc:/qml/main.qml"));

    this->setFixedSize(w, h);

    setWindowTitle("Adapter");

    game = new MazeGame;
    Maze* _maze = game->CreateMaze(*MazeFactory::Instance());

    for(int i = 0; i< _maze->GetRoomSize(); ++i)
    {
        Room* r = _maze->RoomNo(i);
        emit notifyMapSite(i, r->type(), -1);
        emit notifyMapSite(i, r->GetSide(North)->type(), North);
        emit notifyMapSite(i, r->GetSide(South)->type(), South);
        emit notifyMapSite(i, r->GetSide(East)->type(), East);
        emit notifyMapSite(i, r->GetSide(West)->type(), West);
    }
}

Widget::~Widget()
{
    delete ui;
}

void Widget::systemExit(bool b)
{    
    (void)b;
    qApp->quit();
}
